package redisson.rest.stream;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import org.redisson.api.RReliableTopic;
import org.redisson.api.RStream;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("RReliableTopic")
public class RReliableTopicProducer {

	@Autowired
	RedissonClient redissonClient;

	@GetMapping("send")
	public String send() {

		ThreadLocalRandom random = ThreadLocalRandom.current();
		String str = "test:reliabletopic:%s";
		RReliableTopic topic = redissonClient.getReliableTopic(String.format(str, "axxc"));
		int nextInt = random.nextInt(5, 10);
		for (int i = 0; i < nextInt; i++) {
			Map<Object,Object> map= new HashMap<>();
			map.put("cc", "cc");
			map.put("i", i);
			topic.publishAsync(map);
		}
		


		return new String("发送消息成功!");
	}

}
